<template>
  <a-modal
    :visible="visible"
    :title="editId ? '研究方向信息修改' : '新增研究方向信息'"
    okText="保存"
    :width="700"
    @cancel="() => { $emit('cancel') }"
    @ok="() => { $emit('create') }"
  >
    <a-form :form="form">
      <a-row>
        <a-col :md="12" :sm="24">
          <a-form-item
            label="院系"
            :labelCol="{span: 7,offset: 1}"
            :wrapperCol="{span: 15, offset: 1}"
          >
            <a-select v-decorator="[
                'ssyxm',
                {
                  rules: [{ required: true, message: '请选择院系!' }],
                }
              ]" @change="yxChange" showSearch :filterOption="filterOption">
              <a-select-option v-for="i in selectMenu.yx" :key="i.id" :value="i.dwh">{{ i.dwh }} {{ i.dwmc }}</a-select-option>
            </a-select>
          </a-form-item>
        </a-col>
        <a-col :md="12" :sm="24">
          <a-form-item
            label="所属专业"
            :labelCol="{span: 7,offset: 1}"
            :wrapperCol="{span: 15, offset: 1}"
          >
            <a-select v-decorator="[
              'sszym',
              {
                rules: [{ required: true, message: '请选择所属专业!' }],
              }
            ]" @change="zyChange" showSearch :filterOption="filterOption">
              <a-select-option v-for="i in zyList" :key="i.id" :value="i.zyh">{{ i.zyh}} {{ i.zymc }}</a-select-option>
            </a-select>
          </a-form-item>
        </a-col>
      </a-row>
      <a-row>
        <a-col :md="12" :sm="24">
          <a-form-item
            label="研究方向码"
            :labelCol="{span: 7,offset: 1}"
            :wrapperCol="{span: 15, offset: 1}"
          >
            <a-input v-model="researchCode[0]" disabled style="width:33%"/>
            <a-input v-model="researchCode[1]" disabled style="width:33%"/>
            <a-input style="width:33%" v-decorator="['yjfxm',
              {
                rules: [{ required: true, message: '请填写研究方向码!' }],
              }]"/>
          </a-form-item>
        </a-col>
        <a-col :md="12" :sm="24">
          <a-form-item
            label="研究方向名称"
            :labelCol="{span: 7,offset: 1}"
            :wrapperCol="{span: 15, offset: 1}"
          >
            <a-input v-decorator="[
              'yjfxmc',
              {
                rules: [{ required: true, message: '请填写研究方向名称!' }],
              }
            ]"></a-input>
          </a-form-item>
        </a-col>
      </a-row>
      <a-row>
        <a-col :md="12" :sm="24">
          <a-form-item
            label="学位层次"
            :labelCol="{span: 7,offset: 1}"
            :wrapperCol="{span: 15, offset: 1}"
          >
            <a-select v-decorator="[
              'xwccm',
              {
                rules: [{ required: true, message: '请选择学位层次!' }],
              }
            ]">
              <a-select-option v-for="i in selectMenu.xwcc" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
            </a-select>
          </a-form-item>
        </a-col>
        <a-col :md="12" :sm="24">
          <a-form-item
            label="是否全日制"
            :labelCol="{span: 7,offset: 1}"
            :wrapperCol="{span: 15, offset: 1}"
          >
            <a-select v-decorator="[
              'isqrz',
              {
                rules: [{ required: true, message: '请选择是否全日制!' }],
              }
            ]">
              <a-select-option v-for="i in selectMenu.isqrz" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
            </a-select>
          </a-form-item>
        </a-col>
      </a-row>
      <a-row>
        <a-col :md="12" :sm="24">
          <a-form-item
            label="招生学年"
            :labelCol="{span: 7,offset: 1}"
            :wrapperCol="{span: 15, offset: 1}"
          >
            <a-select v-decorator="[
              'zsxn',
              {
                rules: [{ required: true, message: '请选择招生学年!' }],
              }
            ]" @change="xnChange">
              <a-select-option v-for="i in selectMenu.zsxn" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
            </a-select>
          </a-form-item>
        </a-col>
      </a-row>
      <a-form-item label="备注" :labelCol="{span: 2}" :wrapperCol="{span: 21, offset: 1}">
        <a-input type="textarea" v-decorator="['note']" :autosize="{ minRows: 2, maxRows: 6 }"/>
      </a-form-item>
    </a-form>
  </a-modal>
</template>

<script>
export default {
  props: ['visible', 'editId', 'selectMenu'],
  data () {
    return {
      researchCode: new Array(3),
      zyList: []
    }
  },
  beforeCreate () {
    this.form = this.$form.createForm(this)
  },
  methods: {
    yxChange (code, enterEdit = false) {
      if (!enterEdit) {
        this.researchCode[0] = ''
        this.form.resetFields(['sszym'])
      }
      // this.researchCode[1] = ''
      this.$api.base.majorAll({lsdwh: code}).then(res => {
        this.zyList = res.data
      })
    },
    filterOption (value, op) {
      return op.componentOptions.children[0].text.indexOf(value) !== -1
    },
    zyChange (code) {
      this.researchCode[0] = code
    },
    xnChange (code) {
      this.researchCode[1] = code
    }
  }
}
</script>

<style>
</style>
